
#pragma once

#include <define.h>

#include "queue.h"

class CBuffQue
{

public:

	enum
	{
		DEF_BUFF_SIZE = 1024,
	};
	
	struct ST_BUFF
	{	
		size_t	nSize;
		char	szBuff[DEF_BUFF_SIZE];
		
		ST_BUFF()
		{
			nSize = 0;
			memset( szBuff, 0, sizeof(ST_BUFF) );
		}
	};


	CBuffQue() 
	{
		m_nSize = 0;
		m_nCurPos = 0;
	}
	virtual ~CBuffQue() { }

	size_t size() const { return m_que.size(); }
	size_t isEmpty() const { return m_que.isEmpty(); }

	int add( const char* data, const size_t nSize )
	{
		if( DEF_BUFF_SIZE < (m_stBuff.nSize + nSize) )
		{
			m_que.add( m_stBuff );
			memset( &m_stBuff, 0, sizeof(ST_BUFF) );
		}
		
		memcpy( m_stBuff.szBuff, data, nSize );		
		m_stBuff.nSize += nSize;		

		return size();
	}

	int get( char* data, size_t& nSize )
	{
		ST_BUFF st;		
		m_que.get( st );
		
		memcpy( data, st.szBuff, st.nSize );
		nSize = st.nSize;

		return m_que.size();
	}


	
private:
	CQueue<ST_BUFF> m_que;

	ST_BUFF m_stBuff;

	size_t m_nSize;
	size_t m_nCurPos;

};
	
	